<template>
    <view>
		<!-- #ifdef MP-WEIXIN -->
		<view class="ad_wrap">
			<common-ad unitId="adunit-790d87c0f1e0fb25" adType="video" />
		</view>
		<!-- #endif -->
        <view class="lee-card lee-flex" v-if="showCard && cardInfo">
            <slot name="card" :row="cardInfo">
                <image class="lee-logo" :src="cardInfo[params.src]" mode="aspectFit"></image>
                <view class="no">
                    <view>
                        <text>物流公司：</text>
                        <text>{{cardInfo[params.type]}}</text>
                    </view>
                    <view class="padding-top-sm" v-if="cardInfo[params.no]">
                        <text>物流单号：</text>
                        <text>{{cardInfo[params.no]}}</text>
                        <text class="copy" @click="copy(cardInfo[params.no])" :style="{'--pic':mainColor}">复制</text>
                    </view>
					<view class="padding-top-sm" v-if="cardInfo[params.phone]">
					    <text>电话：</text>
					    <text @click="callPhone(cardInfo[params.phone])" class="text-blue">{{cardInfo[params.phone]}}</text>
					    <text class="copy" @click="copy(cardInfo[params.phone])" :style="{'--pic':mainColor}">复制</text>
					</view>
                </view>
            </slot>
        </view>
        <view class="lee-card lee-list-box" v-if="list">
            <view class="list lee-flex" :key="index" v-for="(item,index) in list">
                <view class="left-box">
                    <view class="left">
                        <view class="point" :class="list.length>=1 && index == 0 ? 'point1':''" :style="{'--pic':opacityColor}">
                            <view class="pint-son" :style="{'--pic':mainColor}"></view>
                        </view>
                        <view v-if="list.length > 1 && (index + 1) !== list.length" 
                        :style="{'--pic':mainColor}"
                        class="line" :class="index == 0 ? 'light-line':''"></view>
                    </view>
                </view>
                <slot name="process" :row="item">
                    <view class="right" :class="index == 0 ? 'lee-light':'gray'" :style="{'--pic':mainColor}">
                        <view class="status">{{item[params.status]}}</view>
                        <view class="pd" >{{item[params.content]}}</view>
                        <view class="pd time" :class="index == 0 ? 'lee-light':''" :style="{'--pic':mainColor}">{{item[params.time]}}</view>
                    </view>
                </slot>
            </view>
        </view>
    </view>
</template>

<script>
	import { mapActions, mapState } from 'vuex';
	const status_str = {
		101: '揽件',
		102: '在途中',
		103: '派送中',
		104: '已签收 (完结状态)',
		105: '用户拒签',
		106: '疑难件',
		107: '无效单 (完结状态)', 
		108: '超时单',
		109: '签收失败',
		110: '退回',
		111: '转投',
		112: '待签'
	}
	
    export default {
		data() {
			return {
				params: {src:'src',type:'type',no:'no',phone:'tel',status:'status_str',content:'context',me:'time'},
				showCard: true,
				showCopy: true,
				color: '#ff5a07',
			}
		},
        computed:{
			...mapState(['expressRecord']),
            mainColor(){
                return this.set16ToRgb(this.color)
            },
            opacityColor(){
				return this.set16ToRgb(this.color,0.5)
            },
			list() {
				if (!this.expressRecord || !this.expressRecord.data) {
					return null;
				}
				const result = this.expressRecord.data.map((item) => {
					item.status_str = status_str[item.status] || '';
					return item;
				})
				return result;
			},
			cardInfo() {
				if (!this.expressRecord) {
					return null;
				}
				return {
					src: this.expressRecord.logo,
					type: this.expressRecord.com_name,
					no: this.expressRecord.nu,
					tel: this.expressRecord.tel
				}
			}
        },
        methods: {
			callPhone(tel) {
				uni.showModal({
					content: "确认拨打电话:"+tel,
					success(res) {
						if (res.confirm) {
							uni.makePhoneCall({
								phoneNumber: tel
							});
						}
					}
				})
			},
            // 复制
            copy(text){
				if (!text) {
					return;
				}
                uni.setClipboardData({
                	data: text,
                	success: ()=> {
						uni.showToast({
							icon: 'none',
							title:"复制成功!"
						})
					}
                });
            },
            // 16进制转rgb/rgba
            set16ToRgb(str,opacity){
               var reg = /^#([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/
               if(!reg.test(str)){return;}
               let newStr = (str.toLowerCase()).replace(/\#/g,'')
               let len = newStr.length;
               if(len == 3){
                   let t = ''
                   for(var i=0;i<len;i++){
                       t += newStr.slice(i,i+1).concat(newStr.slice(i,i+1))
                   }
                   newStr = t
               }
               let arr = []; //将字符串分隔，两个两个的分隔
               for(var i =0;i<6;i=i+2){
                   let s = newStr.slice(i,i+2)
                   arr.push(parseInt("0x" + s))
               }
               let res = opacity ? `rgb(${arr.join(",")},${opacity})` : `rgb(${arr.join(",")})`
               return res;
            }
        }
    }
</script>

<style lang="scss" scoped>
$eee:#eee;
.lee-flex{
    display: flex;
}
.gray{
    color: #9f9f9f;
}
.lee-light{
    color: var(--pic)!important;
}
.lee-card{
    margin: 20rpx auto;
    padding: 25rpx 35rpx;
    border-radius: 10rpx;
    background: white;
    .no{
        font-size: 28rpx;
    }
    .copy{
        background: var(--pic);
        color: white;
        padding: 4rpx 14rpx;
        font-size: 28rpx;
        border-radius: 10rpx;
        margin-left: 20rpx;
    }
    .lee-logo{
        width: 90rpx;
        height: 90rpx;
        margin-right: 30rpx;
    }
    .pd{
        padding-bottom: 10rpx;
    }
}
.lee-list-box{
    padding: 5rpx 35rpx;
    .list{
        padding-top: 30rpx;
        position: relative;
        .left-box{
            .left{
                width: 50rpx;
                .point{
                    z-index: 10;
                    width: 30rpx;
                    height: 30rpx;
                    border-radius: 50%;
                    margin-left: calc(20rpx / 2);
                    margin-top: 5rpx;
                    background: $eee;
                    display: flex;
                    justify-content: center;
                    align-items: center;
                    
                }
                .point1{
                    background: var(--pic);
                    margin-top: 0;
                    margin-left: 0rpx;
                    width: 50rpx;
                    height: 50rpx;
                    color: white;
                    .pint-son{
                        width: 60%;
                        height: 60%;
                        background: var(--pic);
                        border-radius: 50%;
                    }
                }
                .line{
                    display: flex;
                    justify-content: center;
                }
                .line::after{
                    content: '';
                    position: absolute;
                    background: $eee;
                    height: calc(100% - 30rpx);
                    width: 4rpx;
                    // margin-top: 10rpx;
                }
                .light-line::after{
                    background: var(--pic);
                }
            }
        }
        
        .right{
            padding-left: 15rpx;
            .status{
                font-weight: bold;
            }
            .time{
                color: #8b8b8b;
                font-size: 28rpx;
            }
        }
    }
    .list:last-child{
        padding-bottom: 30rpx;
    }
}
</style>
